<template>
  <div class="app-container">
    <!-- 搜索区域 -->
<!--    <div class="search-container">-->
<!--      <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">-->
<!--        <el-form-item label="公司名称" prop="companyNameZh">-->
<!--          <el-input-->
<!--            v-model="queryParams.companyNameZh"-->
<!--            placeholder="请输入公司名称"-->
<!--            clearable-->
<!--            @keyup.enter.native="handleQuery"-->
<!--            style="width: 200px"-->
<!--          />-->
<!--        </el-form-item>-->
<!--        <el-form-item label="联系电话" prop="officePhoneZh">-->
<!--          <el-input-->
<!--            v-model="queryParams.officePhoneZh"-->
<!--            placeholder="请输入联系电话"-->
<!--            clearable-->
<!--            @keyup.enter.native="handleQuery"-->
<!--            style="width: 200px"-->
<!--          />-->
<!--        </el-form-item>-->
<!--        <el-form-item>-->
<!--          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>-->
<!--          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>-->
<!--        </el-form-item>-->
<!--      </el-form>-->
<!--    </div>-->

    <!-- 操作按钮区域 -->
<!--    <div class="operation-container">-->
<!--      <el-row :gutter="10" class="mb8">-->
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="primary"-->
<!--            plain-->
<!--            icon="el-icon-plus"-->
<!--            size="mini"-->
<!--            @click="handleAdd"-->
<!--            v-hasPermi="['contactInfo:contactInfo:add']"-->
<!--          >新增</el-button>-->
<!--        </el-col>-->
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="success"-->
<!--            plain-->
<!--            icon="el-icon-edit"-->
<!--            size="mini"-->
<!--            :disabled="single"-->
<!--            @click="handleUpdate"-->
<!--            v-hasPermi="['contactInfo:contactInfo:edit']"-->
<!--          >修改</el-button>-->
<!--        </el-col>-->
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="danger"-->
<!--            plain-->
<!--            icon="el-icon-delete"-->
<!--            size="mini"-->
<!--            :disabled="multiple"-->
<!--            @click="handleDelete"-->
<!--            v-hasPermi="['contactInfo:contactInfo:remove']"-->
<!--          >删除</el-button>-->
<!--        </el-col>-->
<!--        <el-col :span="1.5">-->
<!--          <el-button-->
<!--            type="warning"-->
<!--            plain-->
<!--            icon="el-icon-download"-->
<!--            size="mini"-->
<!--            @click="handleExport"-->
<!--            v-hasPermi="['contactInfo:contactInfo:export']"-->
<!--          >导出</el-button>-->
<!--        </el-col>-->
<!--        <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>-->
<!--      </el-row>-->
<!--    </div>-->

    <!-- 数据展示区域 -->
    <div v-if="contactInfoList.length === 0" class="empty-container">
      <el-empty description="暂无联系信息">
        <el-button type="primary" @click="handleAdd">添加联系信息</el-button>
      </el-empty>
    </div>

    <div v-else class="contact-list">
      <el-card v-for="(item, index) in contactInfoList" :key="index" class="contact-card">
        <div slot="header" class="clearfix">
          <span class="contact-title">{{ item.companyNameZh }}</span>
          <div class="contact-actions">
            <el-button
              type="text"
              icon="el-icon-edit"
              @click="handleUpdate(item)"
              v-hasPermi="['contactInfo:contactInfo:edit']"
            >编辑</el-button>
<!--            <el-button-->
<!--              type="text"-->
<!--              icon="el-icon-delete"-->
<!--              @click="handleDelete(item)"-->
<!--              v-hasPermi="['contactInfo:contactInfo:remove']"-->
<!--              style="color: #f56c6c"-->
<!--            >删除</el-button>-->
          </div>
        </div>

        <div class="contact-details">
          <!-- 中文信息 -->
          <div class="info-section">
            <h3><i class="el-icon-chat-dot-square"></i> 中文信息</h3>
            <div class="info-item">
              <label>物流电话:</label>
              <span>{{ item.logisticsPhoneZh || '-' }}</span>
            </div>
            <div class="info-item">
              <label>办公电话:</label>
              <span>{{ item.officePhoneZh || '-' }}</span>
            </div>
            <div class="info-item">
              <label>电子邮件:</label>
              <span>{{ item.emailZh || '-' }}</span>
            </div>
            <div class="info-item">
              <label>联系地址:</label>
              <span>{{ item.addressZh || '-' }}</span>
            </div>
          </div>

          <!-- 英文信息 -->
          <div class="info-section" v-if="item.companyNameEn || item.logisticsPhoneEn || item.officePhoneEn || item.emailEn || item.addressEn">
            <h3><i class="el-icon-chat-dot-round"></i> 英文信息</h3>
            <div class="info-item">
              <label>公司名称:</label>
              <span>{{ item.companyNameEn || '-' }}</span>
            </div>
            <div class="info-item">
              <label>物流电话:</label>
              <span>{{ item.logisticsPhoneEn || '-' }}</span>
            </div>
            <div class="info-item">
              <label>办公电话:</label>
              <span>{{ item.officePhoneEn || '-' }}</span>
            </div>
            <div class="info-item">
              <label>电子邮件:</label>
              <span>{{ item.emailEn || '-' }}</span>
            </div>
            <div class="info-item">
              <label>联系地址:</label>
              <span>{{ item.addressEn || '-' }}</span>
            </div>
          </div>

          <!-- 德文信息 -->
          <div class="info-section" v-if="item.companyNameDe || item.logisticsPhoneDe || item.officePhoneDe || item.emailDe || item.addressDe">
            <h3><i class="el-icon-chat-line-square"></i> 德文信息</h3>
            <div class="info-item">
              <label>公司名称:</label>
              <span>{{ item.companyNameDe || '-' }}</span>
            </div>
            <div class="info-item">
              <label>物流电话:</label>
              <span>{{ item.logisticsPhoneDe || '-' }}</span>
            </div>
            <div class="info-item">
              <label>办公电话:</label>
              <span>{{ item.officePhoneDe || '-' }}</span>
            </div>
            <div class="info-item">
              <label>电子邮件:</label>
              <span>{{ item.emailDe || '-' }}</span>
            </div>
            <div class="info-item">
              <label>联系地址:</label>
              <span>{{ item.addressDe || '-' }}</span>
            </div>
          </div>
        </div>
      </el-card>
    </div>



    <!-- 添加或修改联系信息对话框 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="1000px"
      append-to-body
      :close-on-click-modal="false"
    >
      <el-tabs v-model="activeTab" type="card">
        <el-tab-pane label="中文信息" name="zh">
          <el-form ref="form" :model="form" :rules="rules" label-width="120px">
            <el-form-item label="公司名称" prop="companyNameZh">
              <el-input v-model="form.companyNameZh" placeholder="请输入公司名称" />
            </el-form-item>
            <el-form-item label="物流电话" prop="logisticsPhoneZh">
              <el-input v-model="form.logisticsPhoneZh" placeholder="请输入物流电话" />
            </el-form-item>
            <el-form-item label="办公电话" prop="officePhoneZh">
              <el-input v-model="form.officePhoneZh" placeholder="请输入办公电话" />
            </el-form-item>
            <el-form-item label="电子邮件" prop="emailZh">
              <el-input v-model="form.emailZh" placeholder="请输入电子邮件" />
            </el-form-item>
            <el-form-item label="联系地址" prop="addressZh">
              <el-input v-model="form.addressZh" type="textarea" :rows="3" placeholder="请输入联系地址" />
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="英文信息" name="en">
          <el-form ref="form" :model="form" label-width="120px">
            <el-form-item label="公司名称" prop="companyNameEn">
              <el-input v-model="form.companyNameEn" placeholder="请输入公司名称" />
            </el-form-item>
            <el-form-item label="物流电话" prop="logisticsPhoneEn">
              <el-input v-model="form.logisticsPhoneEn" placeholder="请输入物流电话" />
            </el-form-item>
            <el-form-item label="办公电话" prop="officePhoneEn">
              <el-input v-model="form.officePhoneEn" placeholder="请输入办公电话" />
            </el-form-item>
            <el-form-item label="电子邮件" prop="emailEn">
              <el-input v-model="form.emailEn" placeholder="请输入电子邮件" />
            </el-form-item>
            <el-form-item label="联系地址" prop="addressEn">
              <el-input v-model="form.addressEn" type="textarea" :rows="3" placeholder="请输入联系地址" />
            </el-form-item>
          </el-form>
        </el-tab-pane>

        <el-tab-pane label="德文信息" name="de">
          <el-form ref="form" :model="form" label-width="120px">
            <el-form-item label="公司名称" prop="companyNameDe">
              <el-input v-model="form.companyNameDe" placeholder="请输入公司名称" />
            </el-form-item>
            <el-form-item label="物流电话" prop="logisticsPhoneDe">
              <el-input v-model="form.logisticsPhoneDe" placeholder="请输入物流电话" />
            </el-form-item>
            <el-form-item label="办公电话" prop="officePhoneDe">
              <el-input v-model="form.officePhoneDe" placeholder="请输入办公电话" />
            </el-form-item>
            <el-form-item label="电子邮件" prop="emailDe">
              <el-input v-model="form.emailDe" placeholder="请输入电子邮件" />
            </el-form-item>
            <el-form-item label="联系地址" prop="addressDe">
              <el-input v-model="form.addressDe" type="textarea" :rows="3" placeholder="请输入联系地址" />
            </el-form-item>
          </el-form>
        </el-tab-pane>
      </el-tabs>

      <div slot="footer" class="dialog-footer">
        <el-button @click="cancel">取 消</el-button>
        <el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listContactInfo, getContactInfo, delContactInfo, addContactInfo, updateContactInfo } from "@/api/contactInfo/contactInfo"

export default {
  name: "ContactInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 联系信息表格数据
      contactInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 当前激活的标签页
      activeTab: 'zh',
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        companyNameZh: null,
        officePhoneZh: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        companyNameZh: [
          { required: true, message: "公司名称(中文)不能为空", trigger: "blur" }
        ],
        officePhoneZh: [
          { required: true, message: "办公电话(中文)不能为空", trigger: "blur" }
        ],
        emailZh: [
          { required: true, message: "电子邮件(中文)不能为空", trigger: "blur" },
          { type: 'email', message: '请输入正确的邮箱地址', trigger: ['blur', 'change'] }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询联系信息列表 */
    getList() {
      this.loading = true
      listContactInfo(this.queryParams).then(response => {
        this.contactInfoList = response.rows
        this.total = response.total
        this.loading = false
      }).catch(() => {
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        companyNameZh: null,
        logisticsPhoneZh: null,
        officePhoneZh: null,
        emailZh: null,
        addressZh: null,
        companyNameEn: null,
        companyNameDe: null,
        logisticsPhoneEn: null,
        logisticsPhoneDe: null,
        officePhoneEn: null,
        officePhoneDe: null,
        emailEn: null,
        emailDe: null,
        addressEn: null,
        addressDe: null
      }
      this.activeTab = 'zh'
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加联系信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getContactInfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = "修改联系信息"
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateContactInfo(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addContactInfo(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除选中的联系信息？').then(() => {
        return delContactInfo(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('contactInfo/contactInfo/export', {
        ...this.queryParams
      }, `contactInfo_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>

<style scoped>
.search-container {
  background: #fff;
  padding: 20px;
  margin-bottom: 15px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.operation-container {
  background: #fff;
  padding: 15px 20px;
  margin-bottom: 15px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.empty-container {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 300px;
  background: #fff;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.contact-list {
  display: grid;
  gap: 15px;
}

.contact-card {
  margin-bottom: 15px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.contact-title {
  font-size: 16px;
  font-weight: bold;
}

.contact-actions {
  float: right;
}

.contact-details {
  display: grid;
  gap: 20px;
}

.info-section {
  padding: 15px;
  border-radius: 4px;
  background-color: #f9f9f9;
}

.info-section h3 {
  margin-top: 0;
  margin-bottom: 15px;
  color: #409EFF;
  border-bottom: 1px solid #eee;
  padding-bottom: 8px;
}

.info-item {
  margin-bottom: 10px;
  display: flex;
}

.info-item label {
  font-weight: bold;
  min-width: 80px;
  color: #666;
}

.info-item span {
  flex: 1;
}

.pagination-container {
  background: #fff;
  padding: 15px 20px;
  margin-top: 15px;
  border-radius: 4px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
  text-align: right;
}

.el-tabs__header {
  margin: 0 0 15px;
}

.el-textarea__inner {
  min-height: 60px !important;
}

.dialog-footer {
  text-align: right;
  padding-top: 15px;
  border-top: 1px solid #e6ebf5;
}
</style>
